using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace etbTOEIC
{
	/// <summary>
	/// Summary description for frmLogin.
	/// </summary>
	public class FormLogin : System.Windows.Forms.Form
	{
		private Lybra.Forms.Controls.GradientPanelXP gradientPanelXP1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox textBoxUser;
		private System.Windows.Forms.TextBox textBoxPass;
		private Lybra.Forms.Controls.HoverGradientButton hoverGradientButtonLogin;
		private Lybra.Forms.Controls.HoverGradientButton hoverGradientButtonCancel;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormLogin()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormLogin));
			this.gradientPanelXP1 = new Lybra.Forms.Controls.GradientPanelXP();
			this.hoverGradientButtonCancel = new Lybra.Forms.Controls.HoverGradientButton();
			this.hoverGradientButtonLogin = new Lybra.Forms.Controls.HoverGradientButton();
			this.textBoxPass = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.textBoxUser = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.gradientPanelXP1.SuspendLayout();
			this.SuspendLayout();
			// 
			// gradientPanelXP1
			// 
			this.gradientPanelXP1.BackColor1 = System.Drawing.Color.FromArgb(((System.Byte)(221)), ((System.Byte)(236)), ((System.Byte)(254)));
			this.gradientPanelXP1.BackColor2 = System.Drawing.Color.FromArgb(((System.Byte)(129)), ((System.Byte)(169)), ((System.Byte)(226)));
			this.gradientPanelXP1.Controls.Add(this.hoverGradientButtonCancel);
			this.gradientPanelXP1.Controls.Add(this.hoverGradientButtonLogin);
			this.gradientPanelXP1.Controls.Add(this.textBoxPass);
			this.gradientPanelXP1.Controls.Add(this.label2);
			this.gradientPanelXP1.Controls.Add(this.textBoxUser);
			this.gradientPanelXP1.Controls.Add(this.label1);
			this.gradientPanelXP1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.gradientPanelXP1.Gradient = System.Drawing.Drawing2D.LinearGradientMode.Vertical;
			this.gradientPanelXP1.Location = new System.Drawing.Point(0, 0);
			this.gradientPanelXP1.Name = "gradientPanelXP1";
			this.gradientPanelXP1.Size = new System.Drawing.Size(352, 150);
			this.gradientPanelXP1.TabIndex = 0;
			// 
			// hoverGradientButtonCancel
			// 
			this.hoverGradientButtonCancel.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
			this.hoverGradientButtonCancel.BackColor2 = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
			this.hoverGradientButtonCancel.BorderHover = true;
			this.hoverGradientButtonCancel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.hoverGradientButtonCancel.Font = new System.Drawing.Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.hoverGradientButtonCancel.Location = new System.Drawing.Point(208, 96);
			this.hoverGradientButtonCancel.Name = "hoverGradientButtonCancel";
			this.hoverGradientButtonCancel.Size = new System.Drawing.Size(88, 32);
			this.hoverGradientButtonCancel.TabIndex = 3;
			this.hoverGradientButtonCancel.TabStop = true;
			this.hoverGradientButtonCancel.Text = "Cancel";
			this.hoverGradientButtonCancel.Click += new System.EventHandler(this.hoverGradientButtonCancel_Click);
			// 
			// hoverGradientButtonLogin
			// 
			this.hoverGradientButtonLogin.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
			this.hoverGradientButtonLogin.BackColor2 = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(64)), ((System.Byte)(64)));
			this.hoverGradientButtonLogin.BorderHover = true;
			this.hoverGradientButtonLogin.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.hoverGradientButtonLogin.Font = new System.Drawing.Font("Arial", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.hoverGradientButtonLogin.Location = new System.Drawing.Point(80, 96);
			this.hoverGradientButtonLogin.Name = "hoverGradientButtonLogin";
			this.hoverGradientButtonLogin.Size = new System.Drawing.Size(88, 32);
			this.hoverGradientButtonLogin.TabIndex = 2;
			this.hoverGradientButtonLogin.TabStop = true;
			this.hoverGradientButtonLogin.Text = "Login";
			this.hoverGradientButtonLogin.Click += new System.EventHandler(this.hoverGradientButtonLogin_Click);
			// 
			// textBoxPass
			// 
			this.textBoxPass.Location = new System.Drawing.Point(104, 48);
			this.textBoxPass.Name = "textBoxPass";
			this.textBoxPass.PasswordChar = '*';
			this.textBoxPass.Size = new System.Drawing.Size(224, 25);
			this.textBoxPass.TabIndex = 1;
			this.textBoxPass.Text = "";
			this.textBoxPass.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxPass_KeyPress);
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.Color.Transparent;
			this.label2.Location = new System.Drawing.Point(8, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(88, 24);
			this.label2.TabIndex = 5;
			this.label2.Text = "Password :";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// textBoxUser
			// 
			this.textBoxUser.Location = new System.Drawing.Point(104, 16);
			this.textBoxUser.Name = "textBoxUser";
			this.textBoxUser.Size = new System.Drawing.Size(224, 25);
			this.textBoxUser.TabIndex = 0;
			this.textBoxUser.Text = "";
			this.textBoxUser.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxPass_KeyPress);
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Location = new System.Drawing.Point(8, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(88, 24);
			this.label1.TabIndex = 4;
			this.label1.Text = "Username :";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// FormLogin
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(7, 18);
			this.ClientSize = new System.Drawing.Size(352, 150);
			this.Controls.Add(this.gradientPanelXP1);
			this.Font = new System.Drawing.Font("Arial", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "FormLogin";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "etbTOEIC Login";
			this.TopMost = true;
			this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxPass_KeyPress);
			this.Load += new System.EventHandler(this.FormLogin_Load);
			this.gradientPanelXP1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void hoverGradientButtonLogin_Click(object sender, System.EventArgs e)
		{
			Login();
			
		}
		private void Login()
		{
			string stUser = textBoxUser.Text.Trim();
			string stPass = textBoxPass.Text.Trim();
			if(MyDatabase.isValidUser(stUser, stPass))
			{
				this.Hide();
				DB2MainForm.stCurrentUser = textBoxUser.Text;
					
				FormMain frmMain = new FormMain();
				frmMain.Show();
				
			}
			else
			{
				MessageBox.Show("Invalid UserName or PassWord","Login");
				textBoxUser.Text = "";
				textBoxPass.Text = "";
				textBoxUser.Focus();
			}
		}

		private void hoverGradientButtonCancel_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void textBoxPass_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			char cKey = e.KeyChar;
			if(cKey == 13)
			{
				Login();
			}
		}

		private void FormLogin_Load(object sender, System.EventArgs e)
		{
		
		}
	}
}
